/*
 * @lc app=leetcode.cn id=20 lang=golang
 *
 * [20] 有效的括号
 */
package main

import "fmt"

// @lc code=start
func isValid(s string) bool {
	if s == "" || len(s)%2 != 0 {
		return true
	}
	var stack []byte
	var stackMap = map[byte]byte{')': '(', '}': '{', ']': '['}
	for i := range s {
		fmt.Println(stackMap[s[i]])
		if stackMap[s[i]] > 0 {
			if len(stack) == 0 || stackMap[s[i]] != stack[len(stack)-1] {
				return false
			}
			stack = stack[:len(stack)-1]
		} else {
			stack = append(stack, s[i])
		}
	}
	return len(stack) == 0
}

// @lc code=end

func main() {
	fmt.Println(isValid("[()]{([])}"))
}
